<?php
namespace Mentees\Controller;

class EventsController extends MainController {

    public function index(){
        $obj = M('EventOrder');
        $map['userid']=$this->userID;
        $count = $obj->where($map)->count();
        import("Common.ORG.Page");
        $page = new \Page($count, 20);
        $show = $page->show();
        $list = $obj->where($map)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
        foreach ($list as $key => $value) {
            unset($map);
            $map['id']=$value['eventID'];
            $list[$key]['event']=M("Event")->where($map)->find();
        }
        $this->assign('list', $list);
        $this->assign('page', $show);  
        $this->display();
    }

    //查看
    public function view(){
       $id = I('get.id');
       if(empty($id) || $id==""){
            $this->error(L('_no_selected'));
       }else{
           $map['id'] = $id;
           $map['userid'] = $this->userID; 
           $obj = M('EventOrder');
           $list=$obj->where($map)->find();
           if($list){
              unset($map);
              $map['id']=$list['eventID'];
              $list['event']=M("Event")->where($map)->find();
              $this->assign('list', $list);
              $this->display();
           }else{
              $this->error(L("_public_noinfo"));
           }
       } 
    }
    //更新
    public function edit(){
        $this->all_save("EventOrder");
    }
    //删除
    public function del(){
       $id = I('get.id');
       if(empty($id) || $id==""){
            $this->error(L('_no_selected'));
       }else{
            $map['id'] = $id;
            $map['userid'] = $this->userID;    
            $obj = M('EventOrder');
            $obj->where($map)->delete();
            $this->success(L("_action_success"),U('Events/index'));
        }
    }
}